<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=latin1">
        <link rel="stylesheet" type="text/css" href="../padrao.css" />
        <link rel="stylesheet" href="../jQuery/lista.css" type="text/css" media="all" />
        <script type="text/javascript" src="../jQuery/jquery-1.2.1.pack.js"></script>
        <script type="text/javascript" src="../jQuery/busca.js"></script>
        <script type="text/javascript" src="../sorttable.js"></script>
        <script type="text/javascript">
            function ChangeColor(tableRow, highLight)
            {
                if (highLight)
                {
                    tableRow.style = '#dcfac9';
                }
                else
                {
                    tableRow.style.backgroundColor = 'white';
                }
            }

            function vai(cpf)
            {
                document.location.href = "view_empresa.php?empresa_selecionada="+cpf;
            }
        </script>

        <title> Pesquisa de Empresas VIP</title>

        <?php
        session_start();
        $default_area = "Escritorio";
        $_SESSION[default_area] = $default_area;
        include '../infobox.php';
        include '../verifica_usuario.php';
        include '../functions.php';
        include '../functions_office.php';
        include '../menu.php';
        ?>

    </head>
    <body>
        <div class="conteudo">
            <p class="titulopesquisa" align='center'> EMPRESAS </p>


            <?php
            //inicializa variavel de ordenaçao
            $ordem = $_SESSION[ordem];
            if ($ordem == "") {
                $ordem = "ASC";
            }

            ///////////
            //inicializa campo da tabela a ser ordenado
            $orderby = $_GET[orderby];
            if ($orderby == "") {
                $orderby = "nome";
            }

            include("mysqlconfig.inc");
            $query = "select * from EMPRESAS
                      WHERE vip_ind = 1
                      ORDER BY $orderby $ordem; ";

            $res = mysql_query($query);
            $num_reg = mysql_num_rows($res);



//            echo "<form method='POST' action='altera_empresa.php'>";
//            echo "<input value='Alterar' type='submit' name='opt'>";
//            echo "<input value='Cadastrar' type='submit' name='opt'>";
            echo "<table> ";

            //titulos das colunas
            echo "<tr >";
            //echo "<td>  </td>";
            echo "<td> <a href='?orderby=nome'>Nomes </a> </td>";
            echo "<td> <a href='?orderby=pj_ind'> F/J </a> </td>";
            echo "<td> <a href='?orderby=cpf_cnpj'> CPF/CNPJ </a> </td>";
            echo "<td> <a href='?orderby=contato'>Contato </a> </td>";
            echo "<td> <a href='?orderby=ddd_fone1'>DDD Comercial </a> </td>";
            echo "<td> <a href='?orderby=fone1'>Fone Comercial </a> </td>";
            echo "<td> <a href='?orderby=ddd_fone2'>DDD Celular </a> </td>";
            echo "<td> <a href='?orderby=fone2'>Fone Celular </a> </td>";
            echo "<td> <a href='?orderby=email'>E-mail </a> </td>";
            echo "<td> <a href='?orderby=cadastro_rapido_ind'>Cadastro Rapido? </a> </td>";
            echo "<td> <a href='?orderby=cadastro_rapido_count'>Entradas Restantes </a> </td>";
            echo "<td> <a href='?orderby=preco_especial_ind'>Preco especial? </a> </td>";
            echo "<td> <a href='?orderby=status'>Status </a> </td>";
            echo "<td> <a href='?orderby=data_criacao'>Data de Criaçao </a> </td>";
            echo "<td> <a href='?orderby=vip_ind'> VIP? </a> </td>";
            echo "<td> <a href='?orderby=vip_limitado'> VIP limitado? </a> </td>";
            echo "<td> <a href='?orderby=vip_limitado_count'> Creditos VIP restantes </a> </td>";
            echo "</tr>";

            for ($i = 0; $i < $num_reg; $i++) {
                $mostra = mysql_fetch_array($res);
                $cpf = $mostra[cpf_cnpj];



                //formatando PJ_IND
                if($mostra[pj_ind] == 1){
                    $pj_ind = "J";
                }  else {
                    $pj_ind = "F";
                }

                //formatando cadastro_rapido_ind
                if($mostra[cadastro_rapido_ind] == 1){
                    $cadastro_rapido_ind = "Sim";
                }  else {
                    $cadastro_rapido_ind = "Não";
                }

                //formatando preco_especial_ind
                if($mostra[preco_especial_ind] == 1){
                    $preco_especial_ind = "Sim";
                }  else {
                    $preco_especial_ind = "Não";
                }


                //ESTILO DA LINHA DA TABELA
                if ($i % 2 == 1) {
                    $tipolinha = "tipo1";
                } else {
                    $tipolinha = "tipo2";
                }
                echo "<tr class='$tipolinha'
                      onmouseover='ChangeColor(this, true)'
                      onmouseout='ChangeColor(this, false);'
                      onClick='vai($cpf);'
                      >";
                echo "<td> $mostra[nome] </td>";
                echo "<td> $pj_ind </td>";
                echo "<td> $mostra[cpf_cnpj] </td>";
                echo "<td> $mostra[contato] </td>";
                echo "<td> $mostra[ddd_fone1] </td>";
                echo "<td> $mostra[fone1] </td>";
                echo "<td> $mostra[ddd_fone2] </td>";
                echo "<td> $mostra[fone2] </td>";
                echo "<td> $mostra[email] </td>";
                echo "<td> $cadastro_rapido_ind </td>";
                echo "<td> $mostra[cadastro_rapido_count] </td>";
                echo "<td> $preco_especial_ind </td>";
                echo "<td> $mostra[status] </td>";
                echo "<td> $mostra[data_criacao] </td>";
                echo "<td> $mostra[vip_ind] </td>";
                echo "<td> $mostra[vip_limitado] </td>";
                echo "<td> $mostra[vip_limitado_count] </td>";
                echo "</tr>";
            }
            echo "</form>";
            echo "</table>";
            echo "$num_reg Empresas cadastradas <br>";


            //troca ordenaçao
            if($ordem == "ASC"){
              $ordem = "DESC";
              $_SESSION[ordem] = $ordem;
            }else {
                $ordem = "ASC";
              $_SESSION[ordem] = $ordem;
            }

            mysql_close($con);
            ?>
        </div>
    </body>
</html>